﻿using Inaction.Criteria;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Inaction.Linq.Clause
{
    abstract class BinaryClause : WhereClause
    {
        public BinaryClause(LinqRoot root, Expression e)
            : base(root, e)
        {

        }

        public override string GetClauseSql()
        {
            #region ==null与!=null的处理
            var rightSql = Right.GetClauseSql();
            if (rightSql == Rule.EnumDescription.GetDescription(CriteriaOperate.IsNull))
            {
                if (Operate == CriteriaOperate.NotEqual)
                {
                    return Left.GetClauseSql() + Rule.EnumDescription.GetDescription(CriteriaOperate.IsNotNull);
                }
                return Left.GetClauseSql() + rightSql;
            }
            #endregion

            return base.GetClauseSql();
        }
    }
}
